from django.views.generic import View

from apps.course.models import Course
from libs import JsonParser, Argument, json_response


class CourseListView(View):
    def get(self, request):
        form, error = JsonParser(
            Argument('ids', help='参数错误'),
        ).parse(request.GET)
        if error is None:
            ids = form.ids.split(',')
            course = Course.objects.filter(id__in=ids)
            if not course:
                return json_response(error='课程不存在')
            return json_response(course)
        return json_response(error=error)
